/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.buzzwords.entities;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author potlow
 */
@Entity
@Table(name = "buzzwords")
public class BuzzwordJPO implements Serializable {

    private static final long serialVersionUID = 1L;
    private Integer id;
    private String word;
    private String definition;
    private Date created;
    private UserJPO user;
    private List<Rating> ratings;
    private List<Tag> tags;

    public BuzzwordJPO() {
    }

    public BuzzwordJPO(Integer id) {
        this.id = id;
    }

    public BuzzwordJPO(String buzzword, String definition, UserJPO user) {
        this.word = buzzword;
        this.definition = definition;
        this.user = user;
    }

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    @Basic(optional = false)
    @Column(name = "word")
    public String getWord() {
        return word;
    }

    @ManyToMany
    @JoinTable(
        name="tag_correlations",
        joinColumns=
            @JoinColumn(name="buzzword_id", referencedColumnName="id"),
        inverseJoinColumns=
            @JoinColumn(name="tag_id", referencedColumnName="id"))
    public List<Tag> getTags() {
        return tags;
    }

    public void setTags(List<Tag> tags) {
        this.tags = tags;
    }

    public void setWord(String word) {
        this.word = word;
    }

    @Basic(optional = false)
    @Column(name = "definition")
    public String getDefinition() {
        return definition;
    }

    public void setDefinition(String definition) {
        this.definition = definition;
    }

    @Column(name = "created")
    @Temporal(TemporalType.TIMESTAMP)
    public Date getCreated() {
        return created;
    }

    public void setCreated(Date created) {
        this.created = created;
    }

    @ManyToMany
    @JoinTable(
        name="rating_correlations",
        joinColumns=
            @JoinColumn(name="buzzword_id", referencedColumnName="id"),
        inverseJoinColumns=
            @JoinColumn(name="rating_id", referencedColumnName="id"))
    public List<Rating> getRatings() {
        return ratings;
    }

    public void setRatings(List<Rating> ratings) {
        this.ratings = ratings;
    }

    @ManyToOne
    @JoinColumn(name="user_id", referencedColumnName="id")
    public UserJPO getUser() {
        return user;
    }

    public void setUser(UserJPO user) {
        this.user = user;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof BuzzwordJPO)) {
            return false;
        }
        BuzzwordJPO other = (BuzzwordJPO) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.buzzwords.persist.Buzzword[id=" + id + "]";
    }

}
